package com.miracle.mango.controller;

import com.miracle.mango.entity.role.Role;
import com.miracle.mango.entity.role.RoleMapper;
import com.miracle.mango.entity.role.RoleServive;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: wangxf
 * @date: Created in 2020/8/23 12:27
 */
@RestController
@Api(tags = "角色管理")
public class RoleController {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private RoleServive roleService;

    @ApiOperation(value = "获取角色详情")
    @GetMapping("/role/{id}")
    public Role getById(@PathVariable("id") String id) {
        return roleMapper.getById(id);
    }

    @ApiOperation(value = "保存角色")
    @PostMapping("/role")
    public int save(Role role) {
        role = new Role();
        role.setRoleName("管理员");
        return roleService.save(role);
    }

    @ApiOperation(value = "更新角色")
    @PutMapping("/role")
    public int update(Role role) {
        role = new Role();
        role.setRoleName("管理员修改后");
        return roleService.update(role);
    }

    @ApiOperation(value = "删除角色")
    @DeleteMapping("/role/{id}")
    public int remove(@PathVariable("id") String id) {
        return roleService.removeById(id);
    }

}
